package com.fly.lambda;

import java.util.Arrays;
import java.util.Comparator;
import java.util.stream.Stream;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.junit.jupiter.api.Test;

import lombok.extern.slf4j.Slf4j;

/**
 * Lambda基础
 */
@Slf4j
public class LambdaBasic
{
    String[] arrayStr = {"a", "d", "c", "o", "r", "e", "p"};
    
    @Test
    public void test()
    {
        // 传统写法
        Arrays.sort(arrayStr, new Comparator<String>()
        {
            @Override
            public int compare(String s1, String s2)
            {
                return s1.compareTo(s2);
            }
        });
        
        // 大括号中的返回语句
        Arrays.sort(arrayStr, (s1, s2) -> {
            return s1.compareTo(s2);
        });
        
        // 类型声明
        Arrays.sort(arrayStr, (String s1, String s2) -> s1.compareTo(s2));
        
        // 不用类型声明
        Arrays.sort(arrayStr, (s1, s2) -> s1.compareTo(s2));
        
        System.out.println(ToStringBuilder.reflectionToString(arrayStr, ToStringStyle.SIMPLE_STYLE));
        Arrays.asList(arrayStr).forEach(System.out::println);
        Arrays.stream(arrayStr).forEach(System.out::println);
        Stream.of(arrayStr).forEach(System.out::println);
        
        Stream.of(arrayStr).forEach(log::info);
    }
}
